import type { Result } from '@/types/common/Result'
import type { GetSongListParams, GetSongListResult } from '@/types/Song'

export const getSongsService = (params: GetSongListParams) => {
  return new Promise<Result<GetSongListResult>>(resolve => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: 'success',
        data: {
          pageNum: params.pageNum!,
          pageSize: params.pageSize!,
          total: 10,
          records: [
            {
              no: 1,
              title: 'Yesterday Once More',
              length: '3:30',
            },
            {
              no: 2,
              title: 'Love Paradise',
              length: '4:30',
            },
            {
              no: 3,
              title: 'My Heart Will Go On',
              length: '5:30',
            },
            {
              no: 4,
              title: 'I Will Always Love You',
              length: '3:30',
            },
            {
              no: 5,
              title: 'Love Story',
              length: '4:30',
            },
            {
              no: 6,
              title: 'Yesterday Once More',
              length: '3:30',
            },
            {
              no: 7,
              title: 'Love Paradise',
              length: '4:30',
            },
            {
              no: 8,
              title: 'My Heart Will Go On',
              length: '5:30',
            },
            {
              no: 9,
              title: 'I Will Always Love You',
              length: '3:30',
            },
            {
              no: 10,
              title: 'Love Story',
              length: '4:30',
            },
          ].splice((params.pageNum! - 1) * params.pageSize!, params.pageSize).filter(item => {
            return item.no === params.no || !params.no
          }),
        },
      })
    }, 1000)
  })
}

export const getRemoteTest = (params: any) => {
  const options = [
    {
      label: 'Drive My Car',
      value: 'song1',
    },
    {
      label: 'Norwegian Wood',
      value: 'song2',
    },
    {
      label: "You Won't See",
      value: 'song3',
    },
    {
      label: 'Nowhere Man',
      value: 'song4',
    },
    {
      label: 'Think For Yourself',
      value: 'song5',
    },
    {
      label: 'The Word',
      value: 'song6',
    },
    {
      label: 'Michelle',
      value: 'song7',
    },
    {
      label: 'What goes on',
      value: 'song8',
    },
    {
      label: 'Girl',
      value: 'song9',
    },
    {
      label: "I'm looking through you",
      value: 'song10',
    },
    {
      label: 'In My Life',
      value: 'song11',
    },
    {
      label: 'Wait',
      value: 'song12',
    },
  ].filter(item => {
    if (params.keyword) {
      return item.label.includes(params.keyword)
    }
    return true
  })
  console.log('options', options)
  const result = {
    code: 200,
    msg: 'success',
    data: options,
  }
  return Promise.resolve(result)
}

export const getRemotePageTest = (params: any) => {
  const options = [
    {
      label: 'Drive My Car',
      value: 'song1',
    },
    {
      label: 'Norwegian Wood',
      value: 'song2',
    },
    {
      label: "You Won't See",
      value: 'song3',
    },
    {
      label: 'Nowhere Man',
      value: 'song4',
    },
    {
      label: 'Think For Yourself',
      value: 'song5',
    },
    {
      label: 'The Word',
      value: 'song6',
    },
    {
      label: 'Michelle',
      value: 'song7',
    },
    {
      label: 'What goes on',
      value: 'song8',
    },
    {
      label: 'Girl',
      value: 'song9',
    },
    {
      label: "I'm looking through you",
      value: 'song10',
    },
    {
      label: 'In My Life',
      value: 'song11',
    },
    {
      label: 'Wait',
      value: 'song12',
    },
  ]
  const records = options
    .filter(item => {
      if (params.keyword) {
        return item.label.includes(params.keyword)
      }
      return true
    })
    .splice((params.pageNum - 1) * params.pageSize, params.pageSize)
  const result = {
    code: 200,
    msg: 'success',
    data: {
      pageNum: params.pageNum,
      pageSize: params.pageSize,
      total: options.length,
      records,
    },
  }
  console.log('result', result)
  return Promise.resolve(result)
}
